﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.UC.盘点.Service;
using DXApplicationTangche.UC.面料库存.盘点.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 盘点Service = DXApplicationTangche.UC.盘点.Service.盘点Service;

namespace DXApplicationTangche.UC.盘点
{
    public partial class Form盘点计划一览 : DevExpress.XtraEditors.XtraForm
    {
        private String stockStoreInventoryPlanCode;//门店盘点计划号
        private String stockInventoryPlanCode;//盘点大计划号
        private List<StockInventoryPlanDTO> stockInventoryPlanDTOs;//盘点大计划预览
        public Form盘点计划一览()
        {
            InitializeComponent();
            this.refreshDate();
        }

        private void simpleButton创建盘点计划_Click(object sender, EventArgs e)
        {
            new Form创建盘点计划().ShowDialog();
        }

        private void refreshDate()
        {
            //给盘点计划一览绑定数据
            this.stockInventoryPlanDTOs = 盘点Service.getStockInventoryPlanDTOALL();
            this.gridControl盘点计划一览.DataSource = this.stockInventoryPlanDTOs;
            this.gridView店铺盘点计划一览.BestFitColumns();
            this.gridView盘点计划一览.BestFitColumns();
            this.gridView店铺盘点计划一览.RefreshData();
            this.gridView盘点计划一览.RefreshData();
        }
        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.refreshDate();
        }

        private void 添加门店盘点计划ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.stockInventoryPlanCode= FunctionHelper
                                        .GetgridViewValue(this.gridView盘点计划一览, 
                                        this.gridView盘点计划一览.FocusedRowHandle, 
                                        "stockInventoryPlanCode"
                                        );
            if (String.IsNullOrEmpty(this.stockInventoryPlanCode))
            {
                return;
            }
            foreach(StockInventoryPlanDTO dTO in this.stockInventoryPlanDTOs)
            {
                if (this.stockInventoryPlanCode.Equals(dTO.stockInventoryPlanCode))
                {
                    new Form创建门店盘点计划(dTO).ShowDialog();
                    this.refreshDate();
                    break;
                }
            }
        }

        private void 盘点大计划完成ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定完成吗？", "盘点计划完成", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.stockInventoryPlanCode = FunctionHelper
                                        .GetgridViewValue(this.gridView盘点计划一览,
                                        this.gridView盘点计划一览.FocusedRowHandle,
                                        "stockInventoryPlanCode"
                                        );
                盘点Service.saveStockInventoryPlanDone(this.stockInventoryPlanCode);
                this.refreshDate();
            }
        }

        private void gridView盘点计划一览_DoubleClick(object sender, EventArgs e)
        {
            this.stockInventoryPlanCode = FunctionHelper
                                        .GetgridViewValue(this.gridView盘点计划一览,
                                        this.gridView盘点计划一览.FocusedRowHandle,
                                        "stockInventoryPlanCode"
                                        );
            if (String.IsNullOrEmpty(this.stockInventoryPlanCode))
            {
                return;
            }
            foreach (StockInventoryPlanDTO dTO in this.stockInventoryPlanDTOs)
            {
                if (this.stockInventoryPlanCode.Equals(dTO.stockInventoryPlanCode))
                {
                    new Form盘点扫码(dTO).ShowDialog();
                    this.refreshDate();
                    break;
                }
            }
        }

        private void 盘盈入库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.stockInventoryPlanCode = FunctionHelper
                                        .GetgridViewValue(this.gridView盘点计划一览,
                                        this.gridView盘点计划一览.FocusedRowHandle,
                                        "stockInventoryPlanCode"
                                        );
            if (String.IsNullOrEmpty(this.stockInventoryPlanCode))
            {
                return;
            }
            foreach (StockInventoryPlanDTO dTO in this.stockInventoryPlanDTOs)
            {
                if (this.stockInventoryPlanCode.Equals(dTO.stockInventoryPlanCode))
                {
                    if (dTO.isDone)
                    {
                        new Form盘点完成(dTO).ShowDialog();
                        this.refreshDate();
                        break;
                    }
                    else
                    {
                        MessageBox.Show("盘点计划未完成,还在进行中");
                        return;
                    }
                }
            }
            
        }
    }
}
